#include "stm32f10x.h"                  // Device header


void Timer_Init(void)
{
	// OPEN CLOCK
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
	TIM_InternalClockConfig(TIM2);
	
	// TIMERBASE_INIT
	TIM_TimeBaseInitTypeDef TIMERBase_InitStruture;
	TIM_TimeBaseStructInit(&TIMERBase_InitStruture);
	TIMERBase_InitStruture.TIM_ClockDivision = TIM_CKD_DIV1;
	TIMERBase_InitStruture.TIM_CounterMode = TIM_CounterMode_Up;
	TIMERBase_InitStruture.TIM_Period = 10000 - 1;						// ARR
	TIMERBase_InitStruture.TIM_Prescaler = 7200  - 1;					// PSC
	TIMERBase_InitStruture.TIM_RepetitionCounter = 0;					// None
	TIM_TimeBaseInit(TIM2, &TIMERBase_InitStruture);
	
	// INTERRUPT SETTING
	TIM_ClearFlag(TIM2, TIM_FLAG_Update);
	TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
	TIM_Cmd(TIM2,ENABLE);
	
	// NVIC INTERRUPT SETTING
	NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
	NVIC_InitTypeDef NVIC_InitTypeStructure;
	NVIC_InitTypeStructure.NVIC_IRQChannel = TIM2_IRQn;
	NVIC_InitTypeStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_InitTypeStructure.NVIC_IRQChannelPreemptionPriority = 1;
	NVIC_InitTypeStructure.NVIC_IRQChannelSubPriority = 1;
	NVIC_Init(&NVIC_InitTypeStructure);
}
